//
//  WSGLoginRegisterViewController.m
//  oneDollar
//
//  Created by Laki on 16/6/15.
//  Copyright © 2016年 com.Laki.corder. All rights reserved.
//

#import "WSGLoginRegisterViewController.h"

#import "WSGLoginRegisterView.h"

@interface WSGLoginRegisterViewController ()
/** 登录注册占位视图View*/
@property (weak, nonatomic) IBOutlet UIView *loginRegiterView;
/** 视图View左侧约束*/
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leading;

@end

@implementation WSGLoginRegisterViewController

+ (instancetype)shareLoginRegisterView{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].firstObject;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 添加登录视图
    WSGLoginRegisterView *loginView = [WSGLoginRegisterView loginView];
    [self.loginRegiterView addSubview:loginView];
    
    // 添加注册视图
    WSGLoginRegisterView *regiterView = [WSGLoginRegisterView regiterView];
    [self.loginRegiterView addSubview:regiterView];
    
    // 接收注册登录按钮点击通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(transForm) name:WSGLoginRegisterViewNotification object:WSGLoginRegisterViewNotification];
}

/*
 * 移除通知
 */
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:WSGLoginRegisterViewNotification object:WSGLoginRegisterViewNotification];
}

/*
 * 布局子控件
 */
- (void)viewDidLayoutSubviews{
    // 占位视图的宽高
    CGFloat width = self.loginRegiterView.bounds.size.width * 0.5;
    CGFloat height = self.loginRegiterView.bounds.size.height;

    // 取出登录视图
    WSGLoginRegisterView *loginView = self.loginRegiterView.subviews[0];
    // 设置Frame
    loginView.frame = CGRectMake(0, 0, width, height);
    
    // 取出注册视图
    WSGLoginRegisterView *regiterView = self.loginRegiterView.subviews[1];
    // 设置Frame
    regiterView.frame = CGRectMake(width, 0, width, height);
}

/*
 * 改变约束
 */
- (void)transForm{
    // 设置约束的值
    self.leading.constant = self.leading.constant == 0 ? -ScreenW : 0;

    // 改变约束
    [UIView animateWithDuration:0.25 animations:^{
        // 刷新约束
        [self.view layoutIfNeeded];
    }];
}
@end
